﻿#ifndef __SINGLETON_H__
#define __SINGLETON_H__

#include <utility>

template<class CObject>
class Singleton
{
protected:
	Singleton(void) {};
	virtual ~Singleton(void) {};
public:
	template<typename ...Args>
	static CObject *instance(Args&&... args)
	{
		if (instance_ == nullptr)
			instance_ = new CObject(std::forward<Args>(args)...);

		return instance_;
	}
	
	static void destory(void)
	{
		if (instance_)
		{
			delete instance_;
			instance_ = nullptr;
		}
	}

private:
	static CObject *instance_;
};

template<class CObject>
CObject *Singleton<CObject>::instance_ = nullptr;

#endif